Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

460
Vistas
Why map is returning [undefined]? and how can i solve that?

I want to filter of my snapshot but i sometimes i am getting [undefined], i dont want to return undefined inside, what is the issue?

return snapshot.docs.map((doc) => {
  const jn = JSON.parse(doc.data().jsonData)
  const res=  jn.attributes.find(t => t.typet === tokenAttrs[0].name);
  if(res){
    return doc.data()
  }
}) 
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Many ways to solve it. One would be to use a foreach and push the new value to an new array. or you filter the empty values from your result before you send it back. like that:

const r = snapshot.docs.map((doc) => {
      const jn = JSON.parse(doc.data().jsonData)
      const res=  jn.attributes.find(t => t.typet === tokenAttrs[0].name);
      if(res){
        return doc.data()
      } else {
        return null;
      }
    }) 
    
// then remove all empty values
return r.filter(n => n)

with forEach()

const res = []; 
snapshot.docs.forEach((doc) => {
  const jn = JSON.parse(doc.data().jsonData)
  const res=  jn.attributes.find(t => t.typet === tokenAttrs[0].name);
  if (res){
    res.push(doc.data());
  }
}) 

return res;
about 4 years ago · Juan Pablo Isaza Denunciar

0

May it can't find the attribute that match the condition,cause the res is undefined. You should check it out.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use the filter function this way:

return snapshot.docs.map(doc => {
    const jn = JSON.parse(doc.data().jsonData);
    const res = jn.attributes.find(t => t.typet === tokenAttrs[0].name);

    if (res) return doc.data();
}).filter(_ => _ !== undefined);

This will remove the undefined values from the array.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda